<template>
	<view class="content">
		<view style="width: 100%;height: 140upx;display: flex;justify-content: center;align-items: center;">
			<view  class="btn" @click="updata">编辑视频</view>
			<view @click="touchstart" class="btn">删除视频</view>
		</view>
		<videop :area='location' :isFlag='isFlag' :allList='videoArray' :playIndex='playIndex' @updateList='bottomScroll' :videoArray='List'></videop>
	</view>
</template>

<script>
	import videop from "@/components/videoList/videop.vue"
	// import * as utils from '../../../utils/index.js'
	export default {
		data(){
			return {
				actIndex:-1,
				cateId: 0,
				location:{},
				page:1,
				List:[],
				isFlag:true,
				playIndex: 0,
				loadingType:0,
				isBoolean: 1,
				videoArray:[],
				shop_id:'',
				userInfo:{},
				page:1
			}
		},
		onLoad(options) {
			try {
				const value = uni.getStorageSync('userInfo');
				if (value) {
					
					this.userInfo = JSON.parse(value)
					console.log(this.userInfo,"视频信息")
					if(this.userInfo.shop_id == 0){
						this.type_id=1
					}else{
						this.type_id = 2
					}
				}
			} catch (e) {
				// error
			}
			uni.request({
				url: 'https://dsx.cdzer.com/api/MemberInfo/user_video', //仅为示例，并非真实接口地址。
				data: {
					uid:this.userInfo.id,
					page:this.page
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded',
				},
				method: 'POST',
				success: (res) => {
					this.page = options.page
					this.shop_id = options.shopId
					this.playIndex = options.index
					
					this.videoArray = res.data.data.video_list
					this.List = this.videoArray
					console.log(this.videoArray[options.index], "视频列表s")
				}
			});
		
			// this.videoArray = this.$store.getters.getPlayList
			// this.List = this.videoArray
			// console.log(this.videoArray,parseInt(this.playIndex),"获取到视频了嘛")
		},
		mounted() {
			// this.getList(1)
		},
		methods:{
			touchstart(index, id) {
					let that = this
				this.Loop = setTimeout(function() {
					uni.showModal({
						title: '删除',
						content: '请问要删除本条视频吗?',
						success: function(res) {
							if (res.confirm) {
								// that.delzz(that.idlist)
								console.log(that.videoArray[that.playIndex].id)
								that.del(that.videoArray[that.playIndex].id)
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
				
						}
					});
				}.bind(this), 100);
				
			},
			updata(){
				uni.navigateTo({
					url:`./updatesp?id=${this.videoArray[this.playIndex].id}`
				})
			},
			del(id){
				uni.request({
					url: 'https://dsx.cdzer.com/merchants/Video/delete', //仅为示例，并非真实接口地址。
					data: {
						id:id
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					method: 'POST',
					success: (res) => {
						console.log(res, "视频列表")
						// this.works = res.data.data
						if(res.data.status == 1){
							uni.showToast({
								title:res.data.mess
							})
							setTimeout(()=>{
								uni.navigateTo({
									url:'./list'
								})
							},1500)
						}else{
							uni.showToast({
								title:res.data.mess,
								icon:'none'
							})
						}
					}
				});
			},
			setFollow(id){
				console.log()
				this.List = this.List.map(item=>{
					if(item.shop_id == id){
						console.log(item,"666")
						item.is_follow = item.is_follow == 0 ? 1:0
					}
					return item
				})
			},
			getList(page){
				uni.request({
					url: serverUrl + '/merchants/Video/videolist', //仅为示例，并非真实接口地址。
					data: {
						shop_id:this.shopId
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					method: 'POST',
					success: (res) => {
						console.log(res, "视频列表s")
						this.List = res.data.video_list
						this.videoArray = this.videoArray.concat(res.data.video_list)
						// ++this.page
												
						this.isUpdate = true
					}
				});
			},
			bottomScroll(){
					this.loadingType = 1
					this.getList(++this.page)
			}
		},
		components: {
			// videoList,
			videop
		},
	}
</script>

<style lang="scss" scoped>
	.btn{
		width: 140upx;
		height: 80upx;
		color: #FFFFFF;
		background-color: #FA3534;
		border-radius: 15upx;
		text-align: center;
		line-height: 80upx;
		margin-left: 28upx;
	}
	.content {
		width: 100%;
		height: 1250upx;
		// margin-top: 250upx;
		overflow: hidden;
		color: #3F536E;
		// background-color: #000000;
		.title {
			margin: 0 20rpx;
		}
	}
	.scroll_box{
		height: calc(100vh - 288rpx);
		// margin-top: ;
		width: 94vw;
		margin: 288rpx 3vw;
	}
</style>
